package com.jfzt.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Map;

/**
 * ElasticSearch映射实体响应结果
 * @author: shunpeng.hu
 * @date: 2024/1/18 17:13
 */
public class ResultMapping implements Serializable {

    private static final Logger logger = LoggerFactory.getLogger(ResultMapping.class);

    private static final long serialVersionUID = 1L;

    /**
     * 总记录
     */
    private Long total = 0L;

    /**
     * 提示信息
     */
    private String msg = null;

    /**
     * 映射文档对象集合
     */
    private Map<String, ResultDocument> documents;

    public ResultMapping() {
    }

    public ResultMapping(Map<String, ResultDocument> documents) {
        this.documents = documents;
    }

    public ResultMapping(Long total, Map<String, ResultDocument> documents) {
        this.total = total;
        this.documents = documents;
    }

    public ResultMapping(Long total, String msg) {
        this.total = total;
        this.msg = msg;
    }

    public ResultMapping(Long total, String msg, Map<String, ResultDocument> documents) {
        this.total = total;
        this.msg = msg;
        this.documents = documents;
    }

    public static <T> ResultMapping success(Long total, Map<String, ResultDocument> documents) {
        return new ResultMapping(total, documents);
    }

    public static <T> ResultMapping success(Map<String, ResultDocument> documents) {
        return new ResultMapping(documents);
    }

    public static <T> ResultMapping success() {
        return new ResultMapping();
    }

    public static <T> ResultMapping error(Long total, String msg) {
        logger.error("返回错误：msg={}", msg);
        return new ResultMapping(null, msg);
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, ResultDocument> getDocuments() {
        return documents;
    }

    public void setDocuments(Map<String, ResultDocument> documents) {
        this.documents = documents;
    }

    @Override
    public String toString() {
        return "ModelMappingResult{" +
                "total=" + total +
                ", msg='" + msg + '\'' +
                ", documents=" + documents +
                '}';
    }
}
